//账户密码管理
package using.association;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.*;
public class password_manage_a extends JFrame {
    public int i = 0;

    public password_manage_a() {
        setTitle("Password management interfa");
        Container container = getContentPane();

        JPanel panel1 = new JPanel();
        setBounds(20, 20, 500, 300);

        JButton jb1 = new JButton("cancel");// 查询按钮
        JButton jb2 = new JButton("confirm");

        panel1.setBorder(BorderFactory.createTitledBorder("Management panel"));
        panel1.setLayout(null);
        JLabel jl2 = new JLabel("user name:");
        JLabel jl3 = new JLabel("New password:");
        JLabel jl4 = new JLabel("Enter again:");

        JTextField jt2 = new JTextField();
        JTextField jt3 = new JTextField();
        JTextField jt4 = new JTextField();

        jb1.setBounds(250, 170, 70, 30);
        jb2.setBounds(130, 170, 70, 30);
        jl2.setBounds(150, 30, 70, 30);
        jt2.setBounds(210, 30, 70, 30);
        jl3.setBounds(150, 70, 70, 30);
        jt3.setBounds(210, 70, 70, 30);
        jl4.setBounds(150, 110, 70, 30);
        jt4.setBounds(210, 110, 70, 30);

        panel1.add(jb1);
        panel1.add(jb2);

        panel1.add(jl2);
        panel1.add(jl3);
        panel1.add(jl4);

        panel1.add(jt2);
        panel1.add(jt3);
        panel1.add(jt4);
        jb2.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent e) {
                String str1, str2, str3, str8 = null;
                str1 = jt2.getText();
                str2 = jt3.getText();
                str3 = jt4.getText();
                String str4 = "select use_id from use where use_id='" + str1 + "'";
                try {
                    SQL_sever.sql = SQL_sever.con.createStatement();
                    SQL_sever.res = SQL_sever.sql.executeQuery(str4);
                    while (SQL_sever.res.next()) {
                        str8 = SQL_sever.res.getString("use_id");
                    }
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
                if (str8 != null) {
                    if (str3.equals(str2)) {
                        String str6 = "update use set use_id=?,use_password=? where use_id='" + jt2.getText() + "'";
                        try {
                            SQL_sever.con =SQL_sever.connection();
                            PreparedStatement sql = SQL_sever.con.prepareStatement(str6);
                            sql.setString(1, str1);
                            sql.setString(2, str2);

                            int result = sql.executeUpdate();

                            validate();
                        } catch (SQLException e1) {
                            e1.printStackTrace();
                        }
                        JOptionPane.showMessageDialog(null, "Modification succeeded, please login again");
                        setVisible(false);
                        association_login.tan();
                        validate();
                    }
                    else
                    {
                        JOptionPane.showMessageDialog(null, "The two passwords are different! Please re-enter");
                    }
                }
                else
                {
                    JOptionPane.showMessageDialog(null, "用户不存在");
                }

            }
        });

        jb1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                setVisible(false);
                password_manage_a.tan();
            }
        });
        container.add(panel1);

        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);// 只释放当前当前窗体的资源
        setVisible(true);
    }

    public static void tan() {
        password_manage_a password = new password_manage_a();
        password.setVisible(true);
    }
}
